package de.mp3player.helpers;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

import de.mp3player.gui.dialogs.Dialogs;
import de.mp3player.repository.IOPlaylist;

public class FileChoose {
	JFileChooser fc = new JFileChooser();
	IOPlaylist io;
	
	public FileChoose(){
		
	}
	public void openFile(){
		fc.setFileFilter(new FileFilter(){
			@Override public boolean accept(File f){
				return f.isDirectory() || f.getName().toLowerCase().endsWith(".m3u");
			}
			@Override public String getDescription(){
				return "mlist";
			}
		});
		
		int state = fc.showOpenDialog(null);
		
		if (state == JFileChooser.APPROVE_OPTION){
			File file = fc.getSelectedFile();
			io = new IOPlaylist(file.getName());
			io.readPlaylist();
		} else {
			Dialogs.getOpenfileError();
		}
	}
	public void saveFile(){
		fc.setFileFilter(new FileFilter(){
			@Override public boolean accept(File f){
				return f.isDirectory() || f.getName().toLowerCase().endsWith(".m3u");
			}
			@Override public String getDescription(){
				return "mlist";
			}
		});
		fc.showSaveDialog(null);		
	}
}
